//
//  SuccessViewController.m
//  图片故事
//
//  Created by 大帅逼 on 16/3/10.
//  Copyright © 2016年 helloApp. All rights reserved.
//

#import "SuccessViewController.h"
#import "Header.h"
#import "UAProgressView.h"
#import "CreateManagerViewController.h"
#import "ReadStoryViewController.h"
#import "ViewController.h"

@interface SuccessViewController ()

@property(nonatomic,strong) UIView          *bgView;
@property(nonatomic,strong) UAProgressView  *progressView;
@property(nonatomic,strong) UIView          *msgView;
@property(nonatomic,strong) UIButton        *backBtn;
@property(nonatomic,strong) UIButton        *homeBtn;
@property(nonatomic,strong) UIButton        *readStoryBtn;

@end

@implementation SuccessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.bgView];
    
    [self.view addSubview:self.progressView];
    
    [self.progressView setProgress:100.0 animated:YES];
    
    [self.view addSubview:self.msgView];
    
    [self showMsgView];
    
    [self.view addSubview:self.homeBtn];
    
    [self.view addSubview:self.backBtn];
    
    [self.view addSubview:self.readStoryBtn];
}

- (void) showMsgView {

    if (self.msgView.alpha > 0) {
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.msgView.alpha = 0;
        }];
    }else {
    
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.msgView.alpha = 1;
        }];
    }
}

- (void) action_backBtnClickEvent {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void) action_homeBtnClickEvent {
    
    [self.navigationController popViewControllerAnimated:YES];
    
    [[CreateManagerViewController shardManger] dismissViewControllerAnimated:NO completion:nil];
}

- (void) action_readStoryBtnClickEvent {

    [self action_homeBtnClickEvent];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"showReadStoryVC" object:nil];
}

#pragma mark -- 懒加载
- (UIView *)bgView {

    if (!_bgView) {
        
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
        
        UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"success_bg"]];
        
        [bgImageView setFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
        
        [_bgView addSubview:bgImageView];
        
        UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
        
        [maskView setBackgroundColor:[UIColor colorWithWhite:0.8 alpha:0.2]];
        
        [_bgView addSubview:maskView];
    }
    
    return _bgView;
}

- (UAProgressView *)progressView {

    if (!_progressView) {
        
        _progressView  = [[UAProgressView alloc] init];
        
        [_progressView setBounds:CGRectMake(0, 0, My_Height(200), My_Height(200))];
        
        [_progressView setCenter:CGPointMake(SCREEN_W / 2, SCREEN_H / 2 - My_Height(100))];
        
        [_progressView setProgress:0 animated:YES];
        
        [_progressView setTintColor:[UIColor colorWithWhite:0.9 alpha:0.8]];
        
        [_progressView setBorderWidth:5];
        
        [_progressView setLineWidth:5];
        
        [_progressView setAnimationDuration:1.0];
    }
    
    return _progressView;
}

- (UIView *)msgView {

    if (!_msgView) {
        
        _msgView = [[UIView alloc] init];
        
        [_msgView setAlpha:0];
        
        [_msgView setBounds:CGRectMake(0, 0, My_Height(100), My_Height(100))];
        
        [_msgView setCenter:CGPointMake(SCREEN_W / 2, SCREEN_H / 2 - My_Height(115))];
        
        UIImageView *successImageView = [[UIImageView alloc] init];
        
        [successImageView setBounds:CGRectMake(0, 0, My_Height(60), My_Height(60))];
        
        [successImageView setCenter:CGPointMake(My_Height(50), My_Height(40))];
        
        [successImageView setImage:[UIImage imageNamed:@"ok_icon"]];
        
        [_msgView addSubview:successImageView];
        
        UILabel *msgLabel = [[UILabel alloc] init];
        
        [msgLabel setBounds:CGRectMake(0, 0, My_Height(100), My_Height(20))];
        
        [msgLabel setCenter:CGPointMake(My_Height(50), My_Height(90))];
        
        [msgLabel setTextColor:[UIColor whiteColor]];
        
        [msgLabel setFont:[UIFont systemFontOfSize:16]];
        
        [msgLabel setTextAlignment:NSTextAlignmentCenter];
        
        [msgLabel setText:@"上传成功"];
        
        [_msgView addSubview:msgLabel];
    
    }
    
    return _msgView;
}

- (UIButton *)backBtn {

    if (!_backBtn) {
        
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_backBtn setFrame:CGRectMake(SCREEN_W / 2 - My_Height(100), SCREEN_H / 2 + My_Height(130), My_Width(200), My_Height(40))];
        
        [_backBtn.layer setCornerRadius:My_Height(20.0)];
        
        [_backBtn setTitle:@"继续去发布" forState:UIControlStateNormal];
        
        [_backBtn addTarget:self action:@selector(action_backBtnClickEvent) forControlEvents:UIControlEventTouchUpInside];
        
        [_backBtn setBackgroundColor:[UIColor colorWithRed:176/255.0 green:196/255.0 blue:222/255.0 alpha:0.7]];
        
        [_backBtn.layer setBorderWidth:1];
        
        [_backBtn.titleLabel setTextColor:[UIColor whiteColor]];
        
        [_backBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
        
        [_backBtn.titleLabel setTextAlignment:NSTextAlignmentCenter];
        
        [_backBtn.layer setBorderColor:[UIColor whiteColor].CGColor];
    }
    
    return _backBtn;
}

- (UIButton *)homeBtn {

    if (!_homeBtn) {
        
        _homeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_homeBtn setFrame:CGRectMake(SCREEN_W - My_Height(60), My_Height(40), My_Height(40), My_Height(40))];
        
        [_homeBtn setImage:[UIImage imageNamed:@"Home_icon"] forState:UIControlStateNormal];
        
        [_homeBtn addTarget:self action:@selector(action_homeBtnClickEvent) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _homeBtn;
}

- (UIButton *)readStoryBtn {
    
    if (!_readStoryBtn) {
        
        _readStoryBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_readStoryBtn setFrame:CGRectMake(SCREEN_W / 2 - My_Height(100), SCREEN_H / 2 + My_Height(70), My_Width(200), My_Height(40))];
        
        [_readStoryBtn.layer setCornerRadius:My_Height(20.0)];
        
        [_readStoryBtn setTitle:@"现在去查看" forState:UIControlStateNormal];
        
        [_readStoryBtn addTarget:self action:@selector(action_readStoryBtnClickEvent) forControlEvents:UIControlEventTouchUpInside];
        
        [_readStoryBtn setBackgroundColor:[UIColor colorWithRed:176/255.0 green:196/255.0 blue:222/255.0 alpha:0.7]];
        
        [_readStoryBtn.layer setBorderWidth:1];
        
        [_readStoryBtn.titleLabel setTextColor:[UIColor whiteColor]];
        
        [_readStoryBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
        
        [_readStoryBtn.titleLabel setTextAlignment:NSTextAlignmentCenter];
        
        [_readStoryBtn.layer setBorderColor:[UIColor whiteColor].CGColor];
    }
    
    return _readStoryBtn;
}

- (void)viewWillAppear:(BOOL)animated {

    [self.navigationController setNavigationBarHidden:YES];
}

- (void)viewWillDisappear:(BOOL)animated {

    [self.navigationController setNavigationBarHidden:NO];
}

@end
